// components/hotspotList/recommend.js
import { articleList } from '../../api/article'
const util = require('../../utils/util.js')
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    tags: {
      type: Array,
      value: []
    },
    articleId: {
      type: Number,
      value: NaN
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    recommandArticleList: []
  },
  observers: {
    'articleId': function (articleId) {
      let duplicate = -1
      articleList({ articleType: 1,PageSize:5}).then(res => {
        let _recommandArticleList = res.data.data
        _recommandArticleList = _recommandArticleList.map((e, i) => {
          if (e.id == articleId) {
            duplicate = i
          }
          return {
            ...e,
            fromNow: util.getDateFromNow(e.createDate),
            thumbnail: util.thumbnail(e.thumbnail, 266, 179)
          }
        });
        if (duplicate != -1) {
          _recommandArticleList.splice(duplicate, 1)
        }
        this.setData({
          recommandArticleList: _recommandArticleList
        })
      })
    }
  },
  lifetimes: {
    attached: function () {
      // debugger
    },
    detached: function () {

    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    tapItem: function (e) {
      this.triggerEvent('tapItem', { id: e.currentTarget.dataset.id })
    }
  }
})
